package com.fr.data.core.define;

import com.fr.base.FRContext;
import com.fr.base.xml.XMLPrintWriter;
import com.fr.base.xml.XMLReadable;
import com.fr.base.xml.XMLableReader;
import com.fr.data.ChartData;
import com.fr.data.TableData;
import com.fr.data.TableDataException;
import com.fr.data.core.DataUtils;
import com.fr.data.core.DataXMLUtils;
import com.fr.data.impl.TableChartData;
import com.fr.data.util.SortOrder;
import com.fr.data.util.function.DataFunction;
import java.util.ArrayList;
import java.util.List;
import java.util.logging.Level;
import java.util.logging.Logger;

/**
 * @deprecated
 */
public class ChartDataDefinition
  implements FilterDefinition
{
  public static final String XML_TAG = "ChartDataDefinition";
  private TableData tableData;
  private SortColumn[] onChangeColumnArray;
  private ChartSummaryColumn[] chartSummaryColumnArray;

  public ChartDataDefinition()
  {
  }

  public ChartDataDefinition(TableData paramTableData, SortColumn[] paramArrayOfSortColumn, ChartSummaryColumn[] paramArrayOfChartSummaryColumn)
  {
    setTableData(paramTableData);
    setOnChangeColumnArray(paramArrayOfSortColumn);
    setChartSummaryColumnArray(paramArrayOfChartSummaryColumn);
  }

  public ChartData createChartData()
  {
    int j;
    int k;
    int l;
    ArrayList localArrayList1 = new ArrayList();
    if (this.tableData == null)
      return null;
    try
    {
      int i = this.tableData.getColumnCount();
      for (j = 0; j < i; ++j)
      {
        String str = this.tableData.getColumnName(j);
        localArrayList1.add(DataUtils.getOnlyColumnName(localArrayList1, str));
      }
    }
    catch (TableDataException localTableDataException)
    {
      FRContext.getLogger().log(Level.WARNING, localTableDataException.getMessage(), localTableDataException);
    }
    ArrayList localArrayList2 = new ArrayList();
    ArrayList localArrayList3 = new ArrayList();
    if (this.onChangeColumnArray != null)
      for (k = 0; k < this.onChangeColumnArray.length; ++k)
      {
        localObject = this.onChangeColumnArray[k];
        l = localArrayList1.indexOf(((SortColumn)localObject).getName());
        if (l >= 0)
        {
          localArrayList2.add(new Integer(l));
          localArrayList3.add(((SortColumn)localObject).getSortOrder());
        }
      }
    ArrayList localArrayList4 = new ArrayList();
    Object localObject = new ArrayList();
    if (this.chartSummaryColumnArray != null)
      for (l = 0; l < this.chartSummaryColumnArray.length; ++l)
      {
        ChartSummaryColumn localChartSummaryColumn = this.chartSummaryColumnArray[l];
        int i2 = localArrayList1.indexOf(localChartSummaryColumn.getName());
        if (i2 >= 0)
        {
          localArrayList4.add(new Integer(i2));
          ((List)localObject).add(localChartSummaryColumn.getFunction());
        }
      }
    int[] arrayOfInt1 = new int[localArrayList2.size()];
    for (int i1 = 0; i1 < arrayOfInt1.length; ++i1)
      arrayOfInt1[i1] = ((Integer)localArrayList2.get(i1)).intValue();
    SortOrder[] arrayOfSortOrder = new SortOrder[localArrayList3.size()];
    localArrayList3.toArray(arrayOfSortOrder);
    int[] arrayOfInt2 = new int[localArrayList4.size()];
    for (int i3 = 0; i3 < arrayOfInt2.length; ++i3)
      arrayOfInt2[i3] = ((Integer)localArrayList4.get(i3)).intValue();
    DataFunction[] arrayOfDataFunction = new DataFunction[((List)localObject).size()];
    ((List)localObject).toArray(arrayOfDataFunction);
    return ((ChartData)new TableChartData(this.tableData, arrayOfInt1, arrayOfSortOrder, arrayOfInt2, arrayOfDataFunction));
  }

  public SortColumn[] getOnChangeColumnArray()
  {
    return this.onChangeColumnArray;
  }

  public void setOnChangeColumnArray(SortColumn[] paramArrayOfSortColumn)
  {
    this.onChangeColumnArray = paramArrayOfSortColumn;
  }

  public ChartSummaryColumn[] getChartSummaryColumnArray()
  {
    return this.chartSummaryColumnArray;
  }

  public void setChartSummaryColumnArray(ChartSummaryColumn[] paramArrayOfChartSummaryColumn)
  {
    this.chartSummaryColumnArray = paramArrayOfChartSummaryColumn;
  }

  public void setTableData(TableData paramTableData)
  {
    this.tableData = paramTableData;
  }

  public TableData getTableData()
  {
    return this.tableData;
  }

  public void readXML(XMLableReader paramXMLableReader)
  {
    if (paramXMLableReader.isChildNode())
    {
      String str2 = paramXMLableReader.getTagName();
      if ((str2.equals("RowColumnArray")) || (str2.equals("ColumnColumnArray")) || (str2.equals("ColColumnArray")) || (str2.equals("OnChangeColumnArray")))
      {
        paramXMLableReader.readXMLObject(new XMLReadable(this)
        {
          private final ChartDataDefinition this$0;

          public void readXML()
          {
            if ((paramXMLableReader.isChildNode()) && (paramXMLableReader.getTagName().equals("SortColumn")))
            {
              String str;
              SortColumn localSortColumn = null;
              if ((str = paramXMLableReader.getAttr("name")) != null)
              {
                localSortColumn = new SortColumn(str);
                if (ChartDataDefinition.access$000(this.this$0) == null)
                {
                  ChartDataDefinition.access$002(this.this$0, new SortColumn[] { localSortColumn });
                }
                else
                {
                  SortColumn[] arrayOfSortColumn = ChartDataDefinition.access$000(this.this$0);
                  ChartDataDefinition.access$002(this.this$0, new SortColumn[arrayOfSortColumn.length + 1]);
                  System.arraycopy(arrayOfSortColumn, 0, ChartDataDefinition.access$000(this.this$0), 0, arrayOfSortColumn.length);
                  ChartDataDefinition.access$000(this.this$0)[arrayOfSortColumn.length] = localSortColumn;
                }
              }
              paramXMLableReader.readXMLObject(new ChartDataDefinition.2(this, localSortColumn));
            }
          }
        });
      }
      else
      {
        Object localObject;
        if (str2.equals("ChartSummaryColumn"))
        {
          String str1;
          localObject = null;
          if ((str1 = paramXMLableReader.getAttr("name")) != null)
          {
            localObject = new ChartSummaryColumn(str1);
            if (this.chartSummaryColumnArray == null)
            {
              this.chartSummaryColumnArray = new ChartSummaryColumn[] { localObject };
            }
            else
            {
              ChartSummaryColumn[] arrayOfChartSummaryColumn = this.chartSummaryColumnArray;
              this.chartSummaryColumnArray = new ChartSummaryColumn[arrayOfChartSummaryColumn.length + 1];
              System.arraycopy(arrayOfChartSummaryColumn, 0, this.chartSummaryColumnArray, 0, arrayOfChartSummaryColumn.length);
              this.chartSummaryColumnArray[arrayOfChartSummaryColumn.length] = localObject;
            }
          }
          if ((str1 = paramXMLableReader.getAttr("function")) == null)
            return;
          try
          {
            ((ChartSummaryColumn)localObject).setFunction(DataXMLUtils.readXMLDataFunction(str1));
          }
          catch (Exception localException)
          {
            throw new RuntimeException(localException.getMessage(), localException);
          }
        }
        if (str2.equals("ChartSummaryColumnArray"))
        {
          paramXMLableReader.readXMLObject(new XMLReadable(this)
          {
            private final ChartDataDefinition this$0;

            public void readXML()
            {
              if ((paramXMLableReader.isChildNode()) && (paramXMLableReader.getTagName().equals("ChartSummaryColumn")))
              {
                String str;
                ChartSummaryColumn localChartSummaryColumn = null;
                if ((str = paramXMLableReader.getAttr("name")) != null)
                {
                  localChartSummaryColumn = new ChartSummaryColumn(str);
                  if (ChartDataDefinition.access$100(this.this$0) == null)
                  {
                    ChartDataDefinition.access$102(this.this$0, new ChartSummaryColumn[] { localChartSummaryColumn });
                  }
                  else
                  {
                    ChartSummaryColumn[] arrayOfChartSummaryColumn = ChartDataDefinition.access$100(this.this$0);
                    ChartDataDefinition.access$102(this.this$0, new ChartSummaryColumn[arrayOfChartSummaryColumn.length + 1]);
                    System.arraycopy(arrayOfChartSummaryColumn, 0, ChartDataDefinition.access$100(this.this$0), 0, arrayOfChartSummaryColumn.length);
                    ChartDataDefinition.access$100(this.this$0)[arrayOfChartSummaryColumn.length] = localChartSummaryColumn;
                  }
                }
                if ((str = paramXMLableReader.getAttr("function")) != null)
                  try
                  {
                    localChartSummaryColumn.setFunction(DataXMLUtils.readXMLDataFunction(str));
                  }
                  catch (Exception localException)
                  {
                    throw new RuntimeException(localException.getMessage(), localException);
                  }
              }
            }
          });
        }
        else if ("TableData".equals(str2))
        {
          localObject = DataXMLUtils.readXMLTableData(paramXMLableReader);
          if (localObject != null)
            setTableData((TableData)localObject);
        }
      }
    }
  }

  public void writeXML(XMLPrintWriter paramXMLPrintWriter)
  {
    int i;
    paramXMLPrintWriter.startTAG("ChartDataDefinition");
    if (this.tableData != null)
      DataXMLUtils.writeXMLTableData(paramXMLPrintWriter, this.tableData);
    if (this.onChangeColumnArray != null)
    {
      paramXMLPrintWriter.startTAG("OnChangeColumnArray");
      for (i = 0; i < this.onChangeColumnArray.length; ++i)
      {
        paramXMLPrintWriter.startTAG("SortColumn").attr("name", this.onChangeColumnArray[i].getName());
        if (this.onChangeColumnArray[i].getSortOrder() != null)
          paramXMLPrintWriter.startTAG("SortOrder").attr("order", this.onChangeColumnArray[i].getSortOrder().getOrder()).end();
        paramXMLPrintWriter.end();
      }
      paramXMLPrintWriter.end();
    }
    if (this.chartSummaryColumnArray != null)
    {
      paramXMLPrintWriter.startTAG("ChartSummaryColumnArray");
      for (i = 0; i < this.chartSummaryColumnArray.length; ++i)
      {
        paramXMLPrintWriter.startTAG("ChartSummaryColumn").attr("name", this.chartSummaryColumnArray[i].getName());
        if (this.chartSummaryColumnArray[i].getFunction() != null)
          paramXMLPrintWriter.attr("function", this.chartSummaryColumnArray[i].getFunction().getClass().getName());
        paramXMLPrintWriter.end();
      }
      paramXMLPrintWriter.end();
    }
    paramXMLPrintWriter.end();
  }

  public void reset()
  {
    this.tableData = null;
    this.onChangeColumnArray = null;
    this.chartSummaryColumnArray = null;
  }

  public Object clone()
    throws CloneNotSupportedException
  {
    Object localObject1;
    Object localObject2;
    int i;
    ChartDataDefinition localChartDataDefinition = (ChartDataDefinition)super.clone();
    if (getOnChangeColumnArray() != null)
    {
      localObject1 = getOnChangeColumnArray();
      localObject2 = new SortColumn[localObject1.length];
      for (i = 0; i < localObject2.length; ++i)
        localObject2[i] = ((SortColumn)localObject1[i].clone());
      localChartDataDefinition.setOnChangeColumnArray(localObject2);
    }
    if (getChartSummaryColumnArray() != null)
    {
      localObject1 = getChartSummaryColumnArray();
      localObject2 = new ChartSummaryColumn[localObject1.length];
      for (i = 0; i < localObject2.length; ++i)
        localObject2[i] = ((ChartSummaryColumn)localObject1[i].clone());
      localChartDataDefinition.setChartSummaryColumnArray(localObject2);
    }
    return localChartDataDefinition;
  }

  static SortColumn[] access$000(ChartDataDefinition paramChartDataDefinition)
  {
    return paramChartDataDefinition.onChangeColumnArray;
  }

  static SortColumn[] access$002(ChartDataDefinition paramChartDataDefinition, SortColumn[] paramArrayOfSortColumn)
  {
    return (paramChartDataDefinition.onChangeColumnArray = paramArrayOfSortColumn);
  }

  static ChartSummaryColumn[] access$100(ChartDataDefinition paramChartDataDefinition)
  {
    return paramChartDataDefinition.chartSummaryColumnArray;
  }

  static ChartSummaryColumn[] access$102(ChartDataDefinition paramChartDataDefinition, ChartSummaryColumn[] paramArrayOfChartSummaryColumn)
  {
    return (paramChartDataDefinition.chartSummaryColumnArray = paramArrayOfChartSummaryColumn);
  }
}